package com.lazy.demo.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lazy.lib.entity.BaseResp;


@Controller
public class HelloWorld {
    private static final Logger logger = LoggerFactory.getLogger(HelloWorld.class);
    
    @RequestMapping("/welcome")
    public ModelAndView helloWorld() {
 
        String message = "<br><div style='text-align:center;'>"
                + "<h3>********** Hello World, Spring MVC Tutorial</h3>This message is coming from HelloWorld.java **********</div><br><br>";
        return new ModelAndView("welcome", "message", message);
    }
    
    @RequestMapping(value = "/welcome/hello", method = RequestMethod.POST)
    public String putJson(@RequestBody Map<String, Object> map){
        logger.info("received: {}", map);
        map.put("name", "lazy");
        logger.info("received: {}", map);
        return "hello";
    }
    
    /**
     * 返回json
    * @Title: getJson 
    * @Description: TODO(这里用一句话描述这个方法的作用) 
    * @return
    * @return Object    返回类型 
    * @author 郝鹏
    * @date 2014-10-8 下午3:50:24
     */
    @RequestMapping(value = "/welcome/json", method = RequestMethod.POST, produces = "application/json")
    @ResponseBody
    public BaseResp getJson(HttpServletRequest request) {
        BaseResp map = BaseResp.success();
        map.put("name", "lazy罗");
        return map;
    }
}
